<?php 
header("content-type:text/html;charset=utf8");

$data = $_POST;

$data['img'] = fileUploda($_FILES);

$res = feedbackInfoDeposit($data);

if ($res) {
	echo '<script>window.location.href="./h5/feedbackSuccess.html"</script>';
}else{
	$url = "./h5/feedback.php?device=".$data['device']."&version=".$data['version']."&city=".$data['city'];
	echo "<script>alert('反馈失败，请重试');window.location.href=".$url."</script>";
}	

//反馈信息入库
function feedbackInfoDeposit($data){
	$pdo = new PDO('mysql:host=123.57.16.97;dbname=project','root','zqVnUy6cxsQXbpEZ');
	$pdo->exec("set names utf8");
	$sql = "INSERT INTO `feedback`(`describe`,`img`,`qq`,`tel`,`device`,`version`,`city`,`time`) VALUES('".$data['describe']."','".$data['img']."','".$data['qq']."','".$data['tel']."','".$data['device']."','".$data['version']."','".$data['city']."','".time()."')";
	return $pdo->exec($sql);
}

//文件上传方法
function fileUploda($file){
	if (!$file['img']['name']) {
		return '';
	}else{
		$fileName = buildImgName($file['img']['type']);
		$res = move_uploaded_file($file['img']['tmp_name'],'./h5/upload/'.$fileName);
		if ($res) {
			return 'https://pay.hispot.cn/app/h5/upload/'.$fileName;
		}else{
			return "文件上传失败";
		}
	}
}

//生成img名称
function buildImgName($type){
	return substr(time(),-8).'.'.substr($type,strpos($type,'/')+1);
}


 ?>